<template>
  <div class="user-container">
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片 -->
    <el-card class="box-card">
      <div style="margin-top: 15px;">
        <el-row :gutter="20">
          <el-col :span="8">
            <el-input placeholder="请输入内容" v-model="orderObj.query" class="iptBox">
              <el-button slot="append" icon="el-icon-search" @click="getOrders()"></el-button>
            </el-input>
          </el-col>
        </el-row>
      </div>
      <!-- 表格 -->
      <el-table :data="tableData" border style="width: 100%;margin:20px 0">
        <el-table-column type="index" width="50" label="#"></el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="180"></el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="180"></el-table-column>
        <el-table-column label="是否付款">
          <template slot-scope="scoped">
            <el-tag v-if="!scoped.row.pay_status" type="success">已付款</el-tag>
            <el-tag v-else type="danger">未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"></el-table-column>
        <el-table-column label="下单时间">
          <template slot-scope="scoped">{{scoped.row.create_time | format}}</template>
        </el-table-column>

        <el-table-column label="操作">
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="orderObj.pagenum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="orderObj.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </el-card>
  </div>
</template>
           
<script>
import { orders_api } from "@/api";
export default {
  data() {
    return {
      tableData: [],
      total: 1,

      /* 分页中的当前页码数 */

      /* 获取数据列表参数对象 */
      orderObj: {
        query: "",
        pagenum: 1,
        pagesize: 5,
      },
    };
  },
  created() {
    this.getOrders();
  },
  methods: {
    /* 分页组件提供的事件 */
    handleSizeChange(val) {
      //console.log(`每页 ${val} 条`)
      this.orderObj.pagesize = val;
      this.getOrders();
    },
    handleCurrentChange(val) {
      //console.log(`当前页: ${val}`)
      //  将获取的当前页赋值给  pagenum
      this.orderObj.pagenum = val;
      this.getOrders();
    },
    /* 获取用户数据列表 */
    async getOrders() {
      const { data: res } = await orders_api(this.orderObj);
      // console.log(res, 888)
      //  将获取的用户数据赋值给tableData
      this.tableData = res.data.goods;
      this.total = res.data.total;
    },
  },
};
</script>
<style scoped lang='less'>
.user-container {
  .el-breadcrumb {
    margin-bottom: 20px;
  }
}
</style>